package com.xl.basic.controller;

import com.xl.basic.annotation.LogIgnored;
import com.xl.basic.annotation.LoginIgnored;
import com.xl.basic.entity.Result;
import com.xl.basic.entity.ResultEnums;
import com.xl.basic.utils.AreaUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 钟勇
 * Create in 2023/9/12 14:49
 */
@Tag(name = "省市区")
@RestController
@RequestMapping("/Area")
@LoginIgnored
@LogIgnored
public class AreaController {

    @Operation(summary = "查询省份列表")
    @PostMapping(value = "/queryProvinceList")
    Result<List<AreaUtils.ProvinceInfo>> queryProvinceList() {
        return ResultEnums.Success.getListResult(AreaUtils.queryProvinceList());
    }

    @Operation(summary = "查询城市列表")
    @PostMapping(value = "/queryCityListByProvinceId")
    Result<List<AreaUtils.CityInfo>> queryCityListByProvinceId(@NotNull(message = "省份ID不能为空") Integer provinceId) {
        return ResultEnums.Success.getListResult(AreaUtils.queryCityListByProvinceId(provinceId));
    }

    @Operation(summary = "查询区域列表")
    @PostMapping(value = "/queryAreaListByCityId")
    Result<List<AreaUtils.AreaInfo>> queryAreaListByCityId(@NotNull(message = "城市ID不能为空") Integer cityId) {
        return ResultEnums.Success.getListResult(AreaUtils.queryAreaListByCityId(cityId));
    }

    @Operation(summary = "查询省市区json")
    @PostMapping(value = "/queryJson")
    Result<List<AreaUtils.AreaInfo>> queryJson() {
        return ResultEnums.Success.getListResult(AreaUtils.getAreaList());
    }

}
